package top.jle.wx.proxy.api.menu;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import top.jle.wx.proxy.annotation.AccessToken;
import top.jle.wx.proxy.api.ResponseBack;
import top.jle.wx.proxy.constant.MenuOption.MenuType;
import top.jle.wx.proxy.domain.menu.ConditionalMenus;
import top.jle.wx.proxy.domain.menu.Menu;
import top.jle.wx.proxy.facade.MenuFacade;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Tag(name = "自定义菜单API")
@AccessToken
public class MenuAPI {

    @Autowired
    private MenuFacade menuFacade;

    @Operation(summary = "获取所有自定菜单类型")
    @GetMapping("/types")
    public ResponseBack<MenuType[]> loadMenuTypes(){
        return ResponseBack.success(MenuType.values());
    }

    @Operation(summary = "创建自定义菜单")
    @PostMapping(value = "/create",consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseBack<Boolean> createMenus(@RequestBody List<Menu> menus){
        menuFacade.createMenus(menus);
        return ResponseBack.success(true);
    }

    @Operation(summary = "查询自定义菜单")
    @GetMapping(value = "/get")
    public ResponseBack<List<Menu>> getMenus(){
        return ResponseBack.success(menuFacade.getMenus());
    }

    @Operation(summary = "创建个性化菜单，并返回menuid（删除时使用）")
    @PostMapping("/add_conditional")
    public ResponseBack<String> createConditionalMenus(@RequestBody ConditionalMenus conditionalMenus){
        String menuId = menuFacade.createConditionalMenus(conditionalMenus);
        return ResponseBack.success(menuId);
    }

    @Operation(summary = "删除个性化菜单")
    @PostMapping("/delete_conditional")
    public ResponseBack<String> deleteConditionalMenus(@Parameter(description="menuId") @RequestParam String menuId){
        menuFacade.deleteConditionalMenus(menuId);
        return ResponseBack.success(menuId);
    }


}
